new Vue({
    el: '#app',
    data: {
        drjcNode:[],
        drjcNodeNow:[],
        count:'',
        countNow:'',
        pagesize: 10,
        drjcNodeTable:[],
        cxtj:{//查询条件
            idCard:'',
            name:'',
            glqk:'',
        }
    },
    methods: {
        selectPage: function (key, keyPath) {
            $(window).attr('location', keyPath);
        },
        getDrjcNode:function (){
            var _this = this;
            $.ajax({
                url:'/entry/getDrjcNode',
                data:{},
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    _this.drjcNode = data;
                    _this.drjcNodeNow = data;
                    _this.count = data.length;
                    _this.countNow = data.length;
                    for(var i = 0; i < _this.pagesize && i < _this.countNow; i++){
                        _this.drjcNodeTable.push(data[i]);
                    }
                },error:function(){

                }
            });
        },
        //翻页
        fanye:function(skipNum = 0, limitNum = 10){
            var _this = this;
            _this.drjcNodeTable=[];
            for(var i = skipNum; i < skipNum+limitNum && i < _this.countNow; i++){
                _this.drjcNodeTable.push(_this.drjcNodeNow[i]);
            }
        },
        handleDrjcNodeCurrentChange: function (currentPage) {
            var _this = this;
            _this.fanye((currentPage - 1) * _this.pagesize, _this.pagesize);
        },
        //搜索
        cxIdCard:function(){
            var _this = this;
            console.log(_this.cxtj.idCard)
            if(_this.cxtj.idCard=='' && _this.cxtj.name=='' && _this.cxtj.glqk == ''){
                _this.drjcNodeNow = _this.drjcNode;
                _this.countNow = _this.count;
                _this.fanye();
            }else{
                _this.drjcNodeNow = [];
                for(var i = 0; i < _this.count; i++){
                    if(_this.drjcNode[i].idCard.indexOf(_this.cxtj.idCard)>=0 &&
                    _this.drjcNode[i].name.indexOf(_this.cxtj.name)>=0 &&
                    _this.drjcNode[i].glqk.indexOf(_this.cxtj.glqk)>=0){
                        _this.drjcNodeNow.push(_this.drjcNode[i]);
                    }
                }
                _this.countNow = _this.drjcNodeNow.length;
                _this.fanye();
            }
            //如果字符串中不包含目标字符会返回-1
            
        },
        newdialog1:function(val){

        },
        deleteNode:function(val){
            console.log(val)
            var _this = this;
            $.ajax({
                url:'/entry/deleteNode',
                data:{
                    id: val.id,
                },
                type: 'post',
                dataType: 'Json',
                success: function (data) {
                    if(data.code == 1){
                        _this.$message({
                            showClose: true,
                            message: '删除成功',
                            type: 'success'
                        });
                    }else{
                        _this.$message.error('删除失败，该节点可能存在与其他节点的关系！');
                    }
                },error:function(){
                }
            });
        },
    },
    mounted() {
        this.getDrjcNode();
    },
})